//
//  PostContentCel.m
//  sensen_ios
//
//  Created by mc on 16/3/25.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "PostContentCel.h"
#import "ZKTextImgReplaceHandle.h"



@implementation PostContentCel

+(instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString * cellIdentifier = @"PostContentCel";
    PostContentCel * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell ==nil) {
        cell = [[self alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
    
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;

    }
    return self;
}

- (void)setPostModel:(PostModel *)postModel{
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    
    _postModel = postModel;
    NSString * string =  [NSString stringWithFormat:@"原帖：%@", postModel.subject];
     CGFloat number = [ZKTextImgReplaceHandle getImgTextHeightWithText:string regex:nil size:CGSizeMake(SCREEN_WIDTH - 26, 10000) fontSize:16];
    self.lable = [[UILabel alloc] initWithFrame:CGRectMake(13, 2, SCREEN_WIDTH - 26, number)];
    [self.contentView addSubview:_lable];
    _lable.textColor = [UIColor darkGrayColor];
    _lable.font = FONT(16);
    _lable.numberOfLines = 0;

    

    NSMutableAttributedString *attr = [ZKTextImgReplaceHandle handleText:string withRegex:nil];
    if (attr) {
        _lable.attributedText = attr;
    } else {
        _lable.text = string;
    }

    
    
}

- (void)setPostReplyModel:(PostReplyModel *)postReplyModel{
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }

    _postReplyModel = postReplyModel;
    NSString * string =  [NSString stringWithFormat:@"原帖：%@", postReplyModel.thread_subject];
    CGFloat number = [ZKTextImgReplaceHandle getImgTextHeightWithText:string regex:nil size:CGSizeMake(SCREEN_WIDTH - 26, 10000) fontSize:16];

    self.lable = [[UILabel alloc] initWithFrame:CGRectMake(13, 2, SCREEN_WIDTH - 26, number)];
    [self.contentView addSubview:_lable];
    _lable.textColor = [UIColor darkGrayColor];
    _lable.font = FONT(16);
    _lable.numberOfLines = 0;


    
    NSMutableAttributedString *attr = [ZKTextImgReplaceHandle handleText:string withRegex:nil];
    if (attr) {
        _lable.attributedText = attr;
    } else {
        _lable.text = string;
    }

}

@end
